package com.edu.spring.transaction.dao;

import com.edu.spring.transaction.bean.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.sql.SQLException;

@Component
public class EmployeeDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Transactional(timeout = -1, propagation = Propagation.REQUIRED)
    public Employee getEmployeeById(Integer id) throws SQLException {
        String sql = "select * from employees where employee_id=?";
        return jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(Employee.class), id);

    }
}
